package com.sdp.lease.task;

import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sdp.lease.db.l_eq_lease_info.service.ILEqLeaseInfoService;
import com.sdp.lease.db.l_supplier_apply.service.ILSupplierApplyService;
import com.sdp.lease.db.l_tenant_apply_info.service.ILTenantApplyInfoService;
import com.sdp.lease.db.l_wz_lease_info.service.ILWzLeaseInfoService;
import com.sdp.lease.utils.LeaseConstants;
import com.sdp.right.cron.ScheduledOfTask;
import com.sdp.right.websocket.dto.MessageInfo;
import com.sdp.right.websocket.server.MessageWebsocketServer;

@Component
public class ApplyNumberTask implements ScheduledOfTask{
	
	@Autowired
	private MessageWebsocketServer messageWebsocketServer;
	
	@Autowired
	private ILSupplierApplyService iLSupplierApplyService;
	
	@Autowired
	private ILTenantApplyInfoService iLTenantApplyInfoService;
	
	@Autowired
	private ILEqLeaseInfoService iLEqLeaseInfoService;
	
	@Autowired
	private ILWzLeaseInfoService iLWzLeaseInfoService;

	@Override
	public void execute() {
		Map<String, Map<String, String>> empClientIdMap = MessageWebsocketServer.getEmpClientIdMap();
		if(empClientIdMap==null || empClientIdMap.size()==0) {
			return;
		}
		String mes = "";
		int count = iLSupplierApplyService.supplierApplyNumber();
		if(count>0) {
			mes+="供应商申请数量:"+count;
		}
		
		int count2 = iLTenantApplyInfoService.tenantApplyNumber();
		if(count2>0) {
			mes+=",求租人申请数量:"+count2;
		}
		
		int count3 = iLEqLeaseInfoService.eqLeaseInfoNumber();
		if(count3>0) {
			mes+=",需审批或办理的设备求租数量:"+count3;
		}
		
		int count4 = iLWzLeaseInfoService.wzLeaseInfoNumber();
		if(count4>0) {
			mes+=",需审批或办理的物资求购数量:"+count4;
		}
		
		if("".equals(mes)){
			return;
		}
		for (Entry<String, Map<String, String>> entry : empClientIdMap.entrySet()) {
			MessageInfo messageInfo = new MessageInfo();
			messageInfo.setData(mes);
			messageInfo.setEmpNo(entry.getKey());
			messageInfo.setType(LeaseConstants.待处理的单据数量.getCode());
			messageWebsocketServer.sendMessage(messageInfo);
		}
	}

}
